package cn.hchaojie.camp.day02.exercise;

/**
 * 使用坐标法打印一下形状：
 * 
 * . . . *
 . * . * .
 . . * . .
 . * . * .
 * . . . *

 * . . . *
 * * . * *
 * * * * *
 * * . * *
 * . . . *
 
 . . * . .
 . * * * .
 * * * * *
 . * * * .
 . . * . .


 * @author hchaojie
 *
 */
public class PrintStars {
	public static void main(String[] args) {
		int size = 3;	// 控制形状大小
		
		System.out.println("打印x:");
		print1(size);
		
		System.out.println("打印蝴蝶结：");
		print2(size);
		
		System.out.println("打印菱形：");
		print3(size);
	}
	
	public static void print1(int n) {
		for (int y = n; y >= -n; y--) {
			for (int x = -n; x <= n; x++) {
				if (Math.abs(x) == Math.abs(y)) {
					System.out.print(" *");
				} else {
					System.out.print(" .");
				}
			}
			
			System.out.println();
		}
	}
	
	public static void print2(int n) {
		for (int y = n; y >= -n; y--) {
			for (int x = -n; x <= n; x++) {
				if (Math.abs(x) >= Math.abs(y)) {
					System.out.print(" *");
				} else {
					System.out.print(" .");
				}
			}
			
			System.out.println();
		}
	}
	
	public static void print3(int n) {
		for (int y = n; y >= -n; y--) {
			for (int x = -n; x <= n; x++) {
				if (Math.abs(x) + Math.abs(y) <= n) {
					System.out.print(" *");
				} else {
					System.out.print(" .");
				}
			}
			
			System.out.println();
		}
	}
}
